package com.itheima.springboot_13_configuration;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.springboot_13_configuration.config.ServerConfig;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.objenesis.SpringObjenesis;

@SpringBootApplication
//@EnableConfigurationProperties(ServerConfig.class) //干啥的?为spring提供bean对象,干啥的? 与@Component冲突
public class Springboot13ConfigurationApplication {

    @Bean
    @ConfigurationProperties(prefix="datasource")
    public DruidDataSource dataSource(){
        DruidDataSource ds=new DruidDataSource();//看不懂
        //ds.setDriverClassName("com.mysql.jdbc.Driver");
        return ds;
    }

    public static void main(String[] args) {
//        SpringApplication.run(Springboot13ConfigurationApplication.class, args);
        ConfigurableApplicationContext ctx=SpringApplication.run(Springboot13ConfigurationApplication.class,args);//我看不懂
        ServerConfig serverConfig=ctx.getBean(ServerConfig.class);//看不懂
        System.out.println(serverConfig);
        DruidDataSource ds= ctx.getBean(DruidDataSource.class);//不知道这是干啥?
        System.out.println(ds.getDriverClassName());
    }

}
